package com.kfm.am;

import java.util.Iterator;
import java.util.List;

public class ListDemo {

    public static void main(String[] args) {
        // of() 返回一个不可修改的List对象
        List list = List.of(1, 2, 3, 4);
//        list.remove(0);
//        list.add(3);
        // 增强for循环
        for (Object object : list) {
            System.out.println(object);
        }
        System.out.println("=====");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        //
        System.out.println("=====");
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        System.out.println("=====");
        list.forEach(obj -> System.out.println(obj));
    }
}
